package com.itaem.community.modules.infrastructure.authority.mapper.permission;

import com.itaem.community.modules.infrastructure.authority.dto.permission.PermissionBriefDTO;
import com.itaem.community.modules.infrastructure.authority.dto.permission.PermissionCreateDTO;
import com.itaem.community.modules.infrastructure.authority.dto.permission.PermissionDTO;
import com.itaem.community.modules.infrastructure.authority.dto.permission.PermissionUpdateDTO;
import com.itaem.community.modules.infrastructure.authority.dto.role.RoleBriefDTO;
import com.itaem.community.modules.infrastructure.authority.entity.permission.PermissionEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.security.Permission;
import java.util.List;

/**
 * <p>项目名称: community </p>
 * <p>文件名称: PermissionTransformer </p>
 * <p>描述: [类型描述] </p>
 * <p>创建时间: 2020/11/1 </p>
 * <p>作者信息: tomato</p>
 *
 * @author tomato
 * @version v1.0
 */
@Mapper(componentModel = "spring")
public interface PermissionTransformer {

    /**
     * 数据库实体转数据传输实体
     *
     * @param entity 数据库实体
     * @return 简要数据传输实体
     */
    PermissionBriefDTO entityToBriefDto(PermissionEntity entity);

    /**
     * 组装数据传输实体
     *
     * @param entity 权限信息
     * @param roles  拥有此权限的角色信息
     * @return 数据传输实体
     */
    PermissionDTO toDto(PermissionEntity entity, List<RoleBriefDTO> roles);

    /**
     * 获取创建信息
     *
     * @param permissionCreateDto 创建信息
     * @return 数据库实体
     */
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "deleted", expression = "java(Boolean.FALSE)")
    PermissionEntity createDtoToEntity(PermissionCreateDTO permissionCreateDto);

    /**
     * 获取更新信息
     *
     * @param permissionUpdateDto 更新信息
     * @return 数据库实体
     */
    @Mapping(target = "deleted", expression = "java(Boolean.FALSE)")
    PermissionEntity updateDtoToEntity(PermissionUpdateDTO permissionUpdateDto);
}

